<template>
  <div class="iframe_box">
    <div @click.stop="onBtnClicked" class="back-btn">
      <nut-drag class="drag" attract :boundary="{ top: 0, left: 0, bottom: 20, right: 30 }">
        <iconpark-icon name="hoticonhbwvmun01" size="30" />
      </nut-drag>
    </div>
    <nut-overlay v-model:visible="state.show">
      <div class="overlay_body">
        <SvgaItem keyStr="xz" name="xz" :active="true" style="width: 20vh;height: 20vh;" class="overla_content" />
      </div>

    </nut-overlay>
    <iframe id="iframeId" v-if="state.src" :src="state.src" frameborder="0" scrolling="auto" />
  </div>
</template>
<script setup lang='ts'>
import { Local } from '@/utils/storage';
import { computed, onMounted, reactive } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import SvgaItem from "@/components/SvgaItem.vue"
const router = useRouter()
const route = useRoute()
const gogogo: any = computed(() => router.options.history.state.back || '/');
const state: any = reactive({
  show: false,
  src: '',
  left: '',
  top: '',
  rlen: history.length,
  offset: { x: window.innerWidth - 100, y: 45 },
})

const onBtnClicked = () => {
  // let len = state.rlen - history.length - 1
  // router.go(len)
  console.log('onBtnClicked...', gogogo);
  router.push(gogogo.value)
}
const resizeChange = () => {

  if (window.orientation === 90 || window.orientation === -90) {
    state.show = false
    state.src = Local.get('gameUrl')
  } else {
    state.show = true
  }
}

onMounted(() => {
  // resizeChange()
  if (route.query.screenOrientation == '1') {
    state.show = true
    let event = "onorientationchange" in window ? "orientationchange" : "resize"
    window.addEventListener(event, resizeChange, false)

  } else {
    state.src = Local.get('gameUrl')
  }
})
</script>


<style lang="scss" scoped>
.iframe_box {
  bottom: 0;
  height: 100%;
  left: 0;
  min-height: 0 !important;
  overflow-y: scroll;
  overflow: hidden;
  padding-bottom: 0;
  position: fixed;
  right: 0;
  top: 0;
  width: 100%;
  z-index: 4000;
}

#iframeId {
  height: 100%;
  min-height: 0 !important;
  padding-top: 0;
  position: relative;
  width: 100%;
  z-index: 0;
}

.drag {
  margin-top: 2px;
  background-color: #ccc;
  border-radius: 50%;
  padding: 2px 4px;
}

.ys-float-btn {
  z-index: 999;
  position: fixed;
}

@keyframes move {
  0% {
    transform: rotate(0deg);
  }

  100% {
    transform: rotate(360deg);
  }
}

.back-btn,
.nut-drag {
  z-index: 999999999999999999999 !important;
}
</style>
